<?php

use yii\helpers\Html;
use yii\grid\GridView;
use app\models\Type;
use app\models\User;
use app\models\Saleorder;

/* @var $this yii\web\View */
/* @var $searchModel app\models\SaleorderSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title ='订单';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="product-index">

    <h1><?= Html::encode($this->title) ?></h1>
    <?php // echo $this->render('_search', ['model' => $searchModel]); ?>

    <?= GridView::widget([
        'dataProvider' => $dataProvider,
        'filterModel' => $searchModel,
        'columns' => [
            ['class' => 'yii\grid\SerialColumn'],
            'orderid',
            'pname',
            'user_id',
            'user.name',
            [
                'attribute'=>'user.type',
                'value'=>function($model){
                    /* @var $model app\models\Saleorder */
                    return $model->user?User::dropdown('type',$model->user->type):'(未设置)';
                },
            ],
            'price',
            'num',
            [
                'attribute' => 'state',
                'value'=>function($model){
                    /* @var $model app\models\Saleorder */
                    return Saleorder::dropdown('state',$model->state);
                },
                'filter'=>Saleorder::dropdown('state'),
                'filterInputOptions'=>['prompt'=>'全部','class'=>'form-control'],
                'headerOptions'=>['width'=>'10%'],
            ],
            [
                'attribute' => 'created_at',
                'format' => ['date', 'php:Y-m-d']
            ],
            [
                'attribute' => 'updated_at',
                'format' => ['date', 'php:Y-m-d']
            ],

            [
                'class' => 'yii\grid\ActionColumn',
                'template'=>'{view}{show}{deliver}',
                'buttons'=>[
                    'show' => function ($url, $model, $key) {
                        /* @var $model app\models\Saleorder */
                        return Html::a('&nbsp;<span class="glyphicon glyphicon-bishop"></span>',
                            ['showorder/create','order_id'=>$model->orderid],
                            ['title' => '晒单'] );
                    },
                    'deliver' => function ($url, $model, $key) {
                        /* @var $model app\models\Saleorder */
                        return Html::a('&nbsp;<span class="glyphicon glyphicon-send"></span>',
                            ['deliver','id'=>$model->orderid],
                            ['title' => '发货'] );
                    },
                ],
                'visibleButtons'=>[
                    'show'=>function($model,$key,$index){
                        /* @var $model app\models\Saleorder */
                        return $model->canShow();
                    },
                    'deliver'=>function($model,$key,$index){
                        /* @var $model app\models\Saleorder */
                        return $model->canChange(Saleorder::STEAT_SHIPPED);
                    },
                ]
            ],
        ],
    ]); ?>
</div>
